package linkedlist;

/**
 * @author justnow
 * Created on 2020-09-30
 * Description
 * 判断链表是否成环，若成环，则返回false，否则为true
 */
public class Leetcode141_HashCycle {
    public boolean hashCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode fast = head.next.next;
        ListNode slow = head.next;
        while (fast != null && fast.next != null) {
            if (fast == slow) return true;
            fast = fast.next.next;
            slow = slow.next;
        }
        return false;
    }
}
